﻿using System;
using System.IO;

namespace AvaloniaMVVMSample.Models;

public interface SystemModel
{
    public string Name { get; set; }
    public string Path { get; set; }
    public string Size { get; set; }
    public string Extension { get; set; }
}

public static class SystemModelStatic
{
    public static string GetSize(this long l)
    {
        string[] label = ["B","KB","MB","GB","TB"];
        int i = 0;
        while (l > 1024)
        {
            l /= 1024;
            i++;
        }

        return $"{l}{label[i]}";
    }

    public static SystemModel GetSys(this FileSystemInfo info)
    {
        if (info is FileInfo)
            return new FileModel(info.FullName);
        if (info is DirectoryInfo)
            return new FolderModel(info.FullName);
        throw new Exception("没有找到该文件");
    }
}